package com.liuqi.knet.remoting;

import com.liuqi.knet.remoting.exchange.codec.ExchangeCountCodec;
import com.liuqi.knet.serialize.hessian2.Hessian2Serialization;
import io.netty.util.concurrent.DefaultThreadFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * KNet 服务端和客户端配置项
 *
 * @author liuqi
 * @date 2024/12/17 17:29
 **/
@Getter
@Setter
@ToString
public class KNetConfig {

    /**
     * 启用心跳检查验证
     */
    private boolean enableHeartbeat = true;

    /**
     * 消息编解码器
     */
    private Codec codec = new ExchangeCountCodec(new Hessian2Serialization());;

    /**
     * 发送消息后, 确认是否成功发送到 socket
     */
    private boolean sent = false;

    /**
     * 收发消息的超时时间
     */
    private int timeout = 10000;

    /**
     * 心跳超时时间
     */
    private int heartbeatTimeout = 30000;

    /**
     * 客户端/服务端, 处理Channel事件的执行器
     */
    private ExecutorService executor = new ThreadPoolExecutor(4, 4,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(),
            new DefaultThreadFactory("knet-channel-event", true));

}
